<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_measureArea"></title>
    <script type="text/javascript" include="bootstrap,widgets.alert"  src="../js/include-web.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" include="leaflet-geoman" src="../../dist/leaflet/include-leaflet.js"></script>
<script type="text/javascript">
    var host = window.isLocal ? window.server : "https://iserver.supermap.io";
    var map,
        url = host + "/iserver/services/map-world/rest/maps/World";
    map = L.map('map', {
        preferCanvas: true,
        crs: L.CRS.EPSG4326,
        center: [34, 108],
        maxZoom: 18,
        zoom: 3
    });
    new L.supermap.TiledMapLayer(url).addTo(map);
    measureArea();

    function measureArea() {
        map.pm.addControls({  
          position: 'topleft',  
          drawMarker: false,
          drawCircleMarker: false,
          drawPolyline: false,
          drawRectangle: true,
          drawPolygon: true,
          drawCircle: false,
          rotateMode: false,
          editMode: false,
          dragMode: false,
          cutPolygon: false
        }); 
        map.on('pm:create', function(e) {
            var polygon = e.layer;
            var areaMeasureParam = new L.supermap.MeasureParameters(polygon);
            new L.supermap
            .MeasureService(url)
            .measureArea(areaMeasureParam).then(function (serviceResult) {
                widgets.alert.showAlert(serviceResult.result.area + resources.msg_sqm, true);
            });
        });
    }
</script>
</body>
</html>